<?php

use App\Http\Controllers\Admin;
use Illuminate\Support\Facades\Route;

//登录
Route::post('login', [Admin\AuthController::class,'login']);
Route::post('logout', [Admin\AuthController::class,'logout']);
Route::post('refresh', [Admin\AuthController::class,'refresh']);
//系统
Route::group(['middleware' => 'auth:admin'], function ($route) {
    $route->get('systemMenus', [Admin\IndexController::class,'systemMenus']);
    $route->get('webSite', [Admin\IndexController::class,'webSite']);
    $route->get('count', [Admin\StatisticsController::class,'getCount']);
    $route->get('line_chart', [Admin\StatisticsController::class,'lineChart']);
    //上传
    $route->post('upload', [Admin\UploadController::class,'uploadFile']);
    $route->post('upload/networkUrl', [Admin\UploadController::class,'networkImage']);
    //管理员
    $route->group(['prefix' => 'basic'], function ($route) {
        $route->get('info', [Admin\BasicController::class,'info']);
        $route->get('logs', [Admin\BasicController::class,'logs']);
        $route->post('update', [Admin\BasicController::class,'update']);
        $route->post('password', [Admin\BasicController::class,'updatePassword']);
    });
    //内容管理
    $route->group(['prefix' => 'content', 'middleware' => 'permission:content.manage'], function ($route) {
        //广告
        $route->group(['prefix' => 'kv', 'middleware' => 'permission:content.kv'], function ($route) {
            $route->get('list', [Admin\Content\AdvController::class,'data']);
            $route->post('store', [Admin\Content\AdvController::class,'store'])->middleware('permission:content.kv.create');
            $route->put('{id}/update', [Admin\Content\AdvController::class,'update'])->middleware('permission:content.kv.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\Content\AdvController::class,'destroy'])->middleware('permission:content.kv.destroy');
        });
        //文章
        $route->group(['prefix' => 'articles', 'middleware' => 'permission:content.articles'], function ($route) {
            $route->get('list', [Admin\Content\ArticleController::class,'data']);
            $route->get('getAllCate', [Admin\Content\ArticleController::class,'getAllCategory']);
            $route->post('store', [Admin\Content\ArticleController::class,'store'])->middleware('permission:content.articles.create');
            $route->get('{id}/edit', [Admin\Content\ArticleController::class,'edit'])->where('id', '[0-9]+');
            $route->put('{id}/update', [Admin\Content\ArticleController::class,'update'])->middleware('permission:content.articles.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\Content\ArticleController::class,'destroy'])->middleware('permission:content.articles.destroy');
        });
        //文章分类
        $route->group(['prefix' => 'column', 'middleware' => 'permission:content.column'], function ($route) {
            $route->get('list', [Admin\Content\CategoryController::class,'data']);
            $route->post('store', [Admin\Content\CategoryController::class,'store'])->middleware('permission:content.column.create');
            $route->put('{id}/update', [Admin\Content\CategoryController::class,'update'])->middleware('permission:content.column.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\Content\CategoryController::class,'destroy'])->middleware('permission:content.column.destroy');
        });
        //附件管理
        $route->group(['prefix' => 'attachment', 'middleware' => 'permission:content.attachment'], function ($route) {
            $route->get('list', [Admin\Content\FilesController::class,'data']);
            $route->get('getAllGroup', [Admin\Content\FilesController::class,'getAllGroup']);
            $route->delete('destroy', [Admin\Content\FilesController::class,'destroy'])->middleware('permission:content.attachment.destroy');
            $route->post('recover', [Admin\Content\FilesController::class,'recover'])->middleware('permission:content.attachment.recover');
            $route->delete('expurgate', [Admin\Content\FilesController::class,'expurgate'])->middleware('permission:content.attachment.expurgate');
        });
        //附件分组管理
        $route->group(['prefix' => 'attachmentGroup', 'middleware' => 'permission:content.attachmentGroup'], function ($route) {
            $route->get('list', [Admin\Content\FilesGroupController::class,'data']);
            $route->post('store', [Admin\Content\FilesGroupController::class,'store'])->middleware('permission:content.attachmentGroup.create');
            $route->put('{id}/update', [Admin\Content\FilesGroupController::class,'update'])->middleware('permission:content.attachmentGroup.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\Content\FilesGroupController::class,'destroy'])->middleware('permission:content.attachmentGroup.destroy');
        });
    });
    //系统管理
    $route->group(['prefix' => 'system', 'middleware' => 'permission:system.manage'], function ($route) {
        //账号管理
        $route->group(['prefix' => 'user', 'middleware' => 'permission:system.user'], function ($route) {
            $route->get('list', [Admin\System\UserController::class,'data']);
            $route->post('store', [Admin\System\UserController::class,'store'])->middleware('permission:system.user.create');
            $route->put('{id}/update', [Admin\System\UserController::class,'update'])->middleware('permission:system.user.edit')->where('id', '[0-9]+');
            $route->put('{id}/resetPassword', [Admin\System\UserController::class,'resetPassword'])->middleware('permission:system.user.resetPassword')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\System\UserController::class,'destroy'])->middleware('permission:system.user.destroy');
            $route->put('{id}/role', [Admin\System\RoleController::class,'assignRoles'])->middleware('permission:system.user.role')->where('id', '[0-9]+');
        });
        //角色管理
        $route->group(['prefix' => 'role', 'middleware' => 'permission:system.role'], function ($route) {
            $route->get('list', [Admin\System\RoleController::class,'data']);
            $route->post('store', [Admin\System\RoleController::class,'store'])->middleware('permission:system.role.create');
            $route->put('{id}/update', [Admin\System\RoleController::class,'update'])->middleware('permission:system.role.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\System\RoleController::class,'destroy'])->middleware('permission:system.role.destroy');
            $route->get('{id}/permission', [Admin\System\RoleController::class,'permission'])->middleware('permission:system.role.permission')->where('id', '[0-9]+');
            $route->put('{id}/permission', [Admin\System\RoleController::class,'assignPermission'])->middleware('permission:system.role.permission')->where('id', '[0-9]+');
        });
        //权限管理
        $route->group(['prefix' => 'menus', 'middleware' => 'permission:system.menus'], function ($route) {
            $route->get('list', [Admin\System\MenusController::class,'data']);
            $route->post('store', [Admin\System\MenusController::class,'store'])->middleware('permission:system.menus.create');
            $route->put('{id}/update', [Admin\System\MenusController::class,'update'])->middleware('permission:system.menus.edit')->where('id', '[0-9]+');
            $route->delete('destroy', [Admin\System\MenusController::class,'destroy'])->middleware('permission:system.menus.destroy');
        });
        //系统设置
        $route->group(['prefix' => 'config', 'middleware' => 'permission:system.config'], function ($route) {
            $route->get('data', [Admin\System\ConfigController::class,'data']);
            $route->put('{siteKey}/update', [Admin\System\ConfigController::class,'update'])->middleware('permission:system.config.update');
        });
    });
    //运维管理
    $route->group(['prefix' => 'maintain', 'middleware' => 'permission:maintain.manage'], function ($route) {
        //数据库管理
        $route->group(['prefix' => 'database', 'middleware' => 'permission:maintain.database'], function ($route) {
            $route->get('list', [Admin\Maintain\DatabaseController::class,'data']);
            $route->get('show', [Admin\Maintain\DatabaseController::class,'show']);
            $route->post('optimize', [Admin\Maintain\DatabaseController::class,'optimize'])->middleware('permission:maintain.database.optimize');
            $route->post('repair', [Admin\Maintain\DatabaseController::class,'repair'])->middleware('permission:maintain.database.repair');
            $route->post('clear', [Admin\Maintain\DatabaseController::class,'clear'])->middleware('permission:maintain.database.clear');
        });
        $route->group(['prefix' => 'logs', 'middleware' => 'permission:maintain.logs'], function ($route) {
            //登录记录
            $route->group(['prefix' => 'login', 'middleware' => 'permission:maintain.logs.login'], function ($route) {
                $route->get('list', [Admin\Logs\LoginLogController::class,'data']);
            });
            //访问日志
            $route->group(['prefix' => 'access', 'middleware' => 'permission:maintain.logs.access'], function ($route) {
                $route->get('list', [Admin\Logs\AccessLogController::class,'data']);
                $route->get('{id}/show', [Admin\Logs\AccessLogController::class,'show'])->where('id', '[0-9]+');
            });
            //操作日志
            $route->group(['prefix' => 'activity', 'middleware' => 'permission:maintain.logs.activity'], function ($route) {
                $route->get('list', [Admin\Logs\ActivityController::class,'data']);
            });
        });
    });
});
